<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>彩票期号管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../css/themes/icon.css" />
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
	$(function(){
		$('#dg').datagrid({
			url: 'getUser.htm',
			method: 'post',
			title: '购买彩票列表',
			iconCls: 'icon-save',
			width: document.body.offsetWidth,
			height: document.body.offsetHeight,
			striped: true, //奇偶行颜色不同
			fitColumns: true,
			singleSelect: true,
			dataType: 'json',   
			pagination:true,//显示分页  
            pageSize:10,//分页大小  
            pageList:[20,15,10],//每页的个数
			loadMsg:'数据正在加载，请稍等......',
			isField:"sId",
			columns:[[
				/*{
				    field:'sId',
					title:'主键',
					width:80,
					align:'center'
				},*/
				{
					field:'sNo',
					title:'开奖期号',
					width:120,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'开奖期号不能为空!'
                    }
                 },
				 {
					field:'redColor1',
					title:'一号红球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'一号红球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:red";
                    }
                  },
				 {
					field:'redColor2',
					title:'二号红球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'二号红球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:red";
                    }
                  },
				 {
					field:'redColor3',
					title:'三号红球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'三号红球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:red";
                    }
                  },
				 {
					field:'redColor4',
					title:'四号红球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'四号红球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:red";
                    }
                  },
				 {
					field:'redColor5',
					title:'五号红球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'五号红球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:red";
                    }
                  },
				 {
					field:'redColor6',
					title:'六号红球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'六号红球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:red";
                    }
                  },
				 {
					field:'buleColor1',
					title:'蓝球',
					width:80,
					align:'center',
					editor : "validatebox",
					options:{
                        required:true, 
                        missingMessage:'蓝球不能为空!'
                    },
                    styler:function(value,rowData,rowIndex){
                    	return "color:blue";
                    }
                  }
			]],
			toolbar:[{  
                text:'新增',  
                iconCls:'icon-add',  
                handler:addRow
            },'-',{  
                text:'修改',  
                iconCls:'icon-edit',  
                handler:updRow  
            },'-',{  
                text:'删除',  
                iconCls:'icon-remove',  
                handler:delRow  
            },'-',{
				text:'保存',
				iconCls:'icon-save',
				handler:saveRow
			}], 
			onHeaderContextMenu: function(e, field){
				e.preventDefault();
				if (!cmenu){
					createColumnMenu();
				}
				cmenu.menu('show', {
					left:e.pageX,
					top:e.pageY
				});
			},
			onDblClickRow: function (rowIndex) {  
	            if (editIndex != rowIndex) {  
	                $('#dg').datagrid('endEdit', editIndex);  
	                $('#dg').datagrid('beginEdit', rowIndex);  
	            }  
            	editIndex = rowIndex;  
        	}
			
		});
	  });
		
	  //校验可执行行函数
      var editIndex = undefined;
	  function endEditing(){
		  if (editIndex == undefined){return true}
		  if ($('#dg').datagrid('validateRow', editIndex)){
			  $('#dg').datagrid('endEdit', editIndex);
			  editIndex = undefined;
			  return true;
		  } else {
			  return false;
		  }
	  }
	  
	  //添加行
	  function addRow(){
            if(endEditing()){
				$('#dg').datagrid('appendRow',{
					sId: '0',  
	                sNo: ''
				});
				editIndex = $('#dg').datagrid('getRows').length-1;
				$('#dg').datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex);
			}
	  }
	  
	  //修改行
	  function updRow(){
	  		var row = $('#dg').datagrid('getSelected');
			if (row) {
				var rowIndex = $('#dg').datagrid('getRowIndex', row);
            	if (editIndex != rowIndex) {  
	                $('#dg').datagrid('endEdit', editIndex);  
	                $('#dg').datagrid('beginEdit', rowIndex);  
	            }  
            	editIndex = rowIndex;   
			}
	  }
	  
	  //删除行
	  function delRow(){
	  	
	  	 var row = $('#dg').datagrid('getSelected');
		 if(row){
		 
		 	$.messager.confirm("提示","确定删除吗？",function(flag){
		    	if(flag){
			    	var rowIndex = $('#dg').datagrid('getRowIndex', row);
					$('#dg').datagrid('deleteRow', rowIndex);
		    	}
		    });
		    
     	 }else{
     	 	$.messager.alert("提示", "请选中一条数据！");
     	 }
     	 
	  }
	  
	 
	 //保存 
	 function saveRow(){
	 	endEdit();
	 	var inserted = $('#dg').datagrid('getChanges', "inserted");
	 	var deleted = $('#dg').datagrid('getChanges', "deleted");
		var updated = $('#dg').datagrid('getChanges', "updated");
		
		var effectRow = new Object();
		if (inserted.length) {
			effectRow["inserted"] = JSON.stringify(inserted);
		}
		if (deleted.length) {
			effectRow["deleted"] = JSON.stringify(deleted);
		}
		if (updated.length) {
			effectRow["updated"] = JSON.stringify(updated);
        }
        
		if(inserted != "" || deleted != "" || updated != ""){
			commitService(effectRow);
		}else{
			$.messager.alert("提示", "没有要提交的数据！");
		}
	 }
	 
	 //结束编辑
	 function endEdit(){
	     var rows = $('#dg').datagrid('getRows');
	     for ( var i = 0; i < rows.length; i++) {
             $('#dg').datagrid('endEdit', i);
          }
     }
     
     //数据提交函数
     function commitService(effectRow){
     	$.post("commitUser.htm", effectRow, function(data) {
			if(data.iRet == 0){
				$.messager.alert("提示", data.strMsg);
				$('#dg').datagrid('reload');
			}
		}, "JSON").error(function() {
			$.messager.alert("提示", "出错了！");
		});
     }
	  
	</script>
  </head>
  <body>
 	<div id="dg"></div>
  </body>
</html>
